<!DOCTYPE html>
<html lang="en">
	<head>
    	<meta name="layout" content="main_pc">
        <title>火堆工作台</title>       
        <link rel="stylesheet" href="${resource(dir: 'css', file: 'user.center.css')}" type="text/css">
        <link rel="stylesheet" href="${resource(dir: 'css_pc', file: 'project.css')}" type="text/css">
		<script type="text/javascript" src="${resource(dir: 'js', file: 'jquery-1.10.2.js')}"></script>
	    <script type="text/javascript" src="${resource(dir: 'js', file: 'ajaxfileupload.js')}"></script>
	    <style>
	    div .img{
	    	float: left;
	    	width: 220px; 
	    	min-height: 160px;
	    	background-size: cover;
	    	background-repeat: no-repeat;
	    }
	    div .del-btn{
	        float: left;
	        margin-top: 75px;
	    }
	    div .cover{
	    	display:block;
	    	float: left;
	    	margin-left:20px;
	    	margin-bottom:15px;
	    }
	    .form-ctrl .img-box-single input[type=file] {
		    position: absolute;
		    width: 100%;
		    height: 100%;
		    left: 0;
		    top: 0;
		    z-index: 100;
		    opacity: 0;
		}
		
	    .form-ctrl .img-box-m input[type=file] {
		    position: absolute;
		    width: 100%;
		    height: 100%;
		    left: 0;
		    top: 0;
		    z-index: 100;
		    opacity: 0;
		}
		.form-style3 .tips {
		    color: #FB6E50;
		}
	    </style>
    </head>
<body>

	<div class="container-fluid">

		<section class="quick-navi mb20">
			<div class="container">
				<a href="#" class="quick-link"><span>火堆工作台</span><span
					class="caret"></span></a>
				<!--a href="#" class="quick-link">联系我们</a-->
			</div>
		</section>

		<section>
			<div class="container mb50">
				
				<g:render template="navigate"   model="[status: status]"/>
							
				<div class="right-content" id="rightconsole">

					<div class="launch-container">
               
                <div class="content">
                	<!--h3>编辑基金池金额</h3-->
                    <form id="editmoneyform" action='/scfire/manage/saveFundMoney' method="post" class="form-style3">
                        <div class="form-item fix-width">
                        	<input type="hidden" id="fundid" name="fundid" value="${fundpoolInstance.id}">
                            <label for="">爱心池名称: <span class="tips"></span>${fundpoolInstance.name}</label>
                        </div>
                        
                        <div class="form-item fix-width">
                            <label for="">爱心池配捐余额: <span class="tips"></span>
                            	<g:formatNumber number="${(fundpoolInstance.totalCount - fundpoolInstance.donateAssigned)/100}"  maxFractionDigits="2" />元（可用）
                            </label>
                        </div>
                        
                        <div class="form-item fix-width">
                            <label for="">操作类型: <span class="tips">*</span>
                            	<input type="checkbox" onclick="checkchange('plusmoney')" id="plusmoney" name="plusmoney" value="plusmoney" checked/>增加资金
                                <input type="checkbox" onclick="checkchange('minusmoney')" id="minusmoney" name="minusmoney" value="minusmoney"/>减少资金
                            </label>
                        </div>
                        
                        <div class="form-item fix-width">
                            <label for="">金额数量: <span class="tips">*</span>
                            	<input type="text" id="money" name="money" placeholder="请输入正整数" style="width: 70%"/>元
                            </label>
                        </div>
                        
                        <div class="form-item">
                        	<label for="">备注说明: <span class="tips">*</span>
                        		<textarea rows="8" cols="15" name="mark" id="mark" style="width: 60%" /></textarea>
                        	</label>
                        </div>
                        
                        <div class="form-item">
				            <label for="#">短信验证码: <span class="tips">*</span>
				            	<input type="hidden" id="mobile" name="mobile" value="15152675666">
				                <input type="text" placeholder="验证码" id="authCode" style="width: 45%">
				                <button id="sendMsg" type="button" style="width: 15%">发送验证码</button>
				            </label>
				        </div>
                        
                        <div class="form-item">
                            <div class="btn-container">
                                <a onclick="submit()" class="btn btn-save-all" style="background:#EBEBEB">提交</a>
                            </div>
                        </div>
                    </form>
                    
                </div>
            </div>                           
            	</div>
                	
                	
			</div>
			<div class="clearboth"></div>
		</section>


	</div>

	<script type="text/javascript">
	var authCodeStats = false;
	var changePhoneFlag = true;
	(function() {
		
		$('#sendMsg').click(function(){
            //发送短信
            var mobile = $('#mobile').val();
            if(!sendSMS(mobile)){//号码格式验证成功即返回true
                return;
            };

            var obj = $(this).attr('disabled', true);
            var count = null, i = 60;
            obj.text(i + '秒后可重发');
            count = setInterval(function(){
                i--;
                if (i <= 0) {
                    obj.removeAttr('disabled').text('重发验证码');
                    clearInterval(count)
                } else {
                    obj.text(i + '秒后可重发');
                }
            }, 1000)
        });
		
    })();
    
	function checkAuthCode(){
        var mobile = $("#mobile").val();
    	var value = $("#authCode").val();
    	$.ajax({
			url:"/scfire/user/authCode",
			type:'POST',
			data:{
				  "code":value,
				  "mobile":mobile
				  },
			dataType:'text',
			async: false,
			contentType: "application/x-www-form-urlencoded; charset=utf-8",
			success:function(data){
				var result = JSON.parse(data).info.text;
				var code = JSON.parse(data).code;
				if(code=="200"){
				//	alert(result);
					authCodeStats = true;
				}else{
					alert('验证码校验失败！');
					authCodeStats = false;
				}				
			},
			error: function (data){
				alert('验证码校验失败！');
				authCodeStats = false;
			}
		}); 
    }
    
    function sendSMS(mobile){

        if(!checkPhoneNumber(mobile)){
        	alert("号码格式不正确，短信发送失败.");
        	return false;
        }
    	$.ajax({
			url:"/scfire/SmsVerification/sendSmsVerification",
			type:'POST',
			data:{
				  "mobile":mobile
				  },
			dataType:'text',
			async: false,
			contentType: "application/x-www-form-urlencoded; charset=utf-8",
			success:function(data){
				var result = JSON.parse(data).info.text;
				if(data.code=="200"){
					alert('短信发送成功.');
				}else{
					alert(result);
				}				
			},
			error: function (data){
				alert("短信发送失败.请稍后再试");
			}
		});
    	return true;
    }

    function checkPhoneNumber(value){
    	var mobile = value
    	console.log(mobile)
        if(!(/^1[3|5|8][0-9]\d{8}$/.test(mobile))){ 
            //alert("手机号格式错误");
            //isPhoneNumVailded = false;
            return false; 
        }else{
        	//isPhoneNumVailded = true;
            return true;
        } 
    }

    function checkchange(checkbox){
        if(checkbox=='plusmoney'){
            //若增加选中，则减少不选中
            if($("#plusmoney").is(':checked')){
            	$("[name = minusmoney]:checkbox").attr("checked", false);
            }else{
            	//若增加不选中，则减少选中
            	$("[name = minusmoney]:checkbox").attr("checked", true);
            }
        }

        if(checkbox=='minusmoney'){
        	//若减少选中，则增加不选中
            if($("#minusmoney").is(':checked')){
            	$("[name = plusmoney]:checkbox").attr("checked", false);
            }else{
            	//若减少不选中，则增加选中
            	$("[name = plusmoney]:checkbox").attr("checked", true);
            }
        }
            
    }

    function checkmoney(money){
    	if(money == ""){
			alert("请输入金额");
			return false;
		}
		if(isNaN(money)){
			alert("金额请输入数字");
			return false;
		}
		if(!isNaN(money)){
	        var dot = money.indexOf(".");
	        if(dot != -1){
	            alert("金额精确到元！");
	            return false;
	        }
	    }
	    if(money <= 0){
			alert("金额不能小于1元！");
			return false;
		}
		return true;
    }

	function submit(){
		var canUse = ${(fundpoolInstance.totalCount - fundpoolInstance.donateAssigned)/100};
		var money = $("#money").val();
		var mark = $("#mark").val();

		checkAuthCode();
		
		if(!checkmoney(money)){
			return;
		}
		if($("#minusmoney").is(":checked") && canUse < money){
			alert("减少资金不能大于爱心池可用资金！");
			return;
		}
		if(mark==null || mark==""){
			alert("请输入备注！");
			return;
		}
				
        if(!authCodeStats){
    		return;
        }
        
    	$("#editmoneyform").submit();
    }

	function cancelForm(){      
    	//$("#editmoneyform").submit();
    }
	</script>

</body>
</html>